

import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Test
import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver

import static org.hamcrest.MatcherAssert.assertThat
import static org.junit.Assert.assertTrue
import static org.junit.internal.matchers.StringContains.containsString
import org.openqa.selenium.By

import static org.junit.Assert.assertEquals

class CssTest {

    static WebDriver driver
    static PROTOCOL = "http"
    static HOST = "www.compendiumdev.co.uk"

    @BeforeClass
    static void createDriver()
    {
        driver = new FirefoxDriver()
    }

    @Test
    void shouldTestSomeByWithId()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.id("p31"))
        assertEquals("Could not find expected element with attribute name p31 on element " + someElement,
                someElement.getAttribute("name"), "pName31")
    }

    @Test
    void shouldTestSomeByWithName()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.name("ulName1"))
        assertEquals("Could not find expected element with id ul1 on element " + someElement,
                someElement.getAttribute("id"), "ul1")
    }

    @Test
    void shouldTestSomeByWihClassName()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.className("specialDiv"))
        assertEquals("Could not find expected element with id div1 on element " + someElement,
                someElement.getAttribute("id"), "div1")
    }

    @Test
    void shouldTestSomeByWihTagName()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.tagName("li"))
        assertEquals("Could not find expected element with name liName1 on element " + someElement,
                someElement.getAttribute("name"), "liName1")
    }

    @Test
    void shouldTestSomeByWithCssOnId()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.cssSelector("#p31"))
        assertEquals("Could not find expected element with attribute name p31 on element " + someElement,
                someElement.getAttribute("name"), "pName31")
    }

    @Test
    void shouldTestSomeByWithCssOnName()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.cssSelector("[name='ulName1']"))
        assertEquals("Could not find expected element with id ul1 on element " + someElement,
                someElement.getAttribute("id"), "ul1")
    }

    @Test
    void shouldTestSomeByWihCssOnClassName()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.cssSelector(".specialDiv"))
        assertEquals("Could not find expected element with id div1 on element " + someElement,
                someElement.getAttribute("id"), "div1")
    }

    @Test
    void shouldTestSomeByWihCssOnTagName()
    {
        driver.navigate().to("http://compendiumdev.co.uk/selenium/find_by_playground.php")
        def someElement = driver.findElement(By.cssSelector("li"))
        assertEquals("Could not find expected element with name liName1 on element " + someElement,
                someElement.getAttribute("name"), "liName1")
    }

    @AfterClass
    static void quitDriver()
    {
        driver.quit()
    }

}

